<%#
 Copyright 2013-2019 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
<div>
    <h2 id="audits-page-heading" jhiTranslate="audits.title">Audits</h2>

    <<%= jhiPrefixDashed %>-alert-error></<%= jhiPrefixDashed %>-alert-error>

    <div class="row">
        <div class="col-md-5">
            <h4 jhiTranslate="audits.filter.title">Filter by date</h4>
            <div class="input-group mb-3">
                <div class="input-group-prepend">
                    <span class="input-group-text" jhiTranslate="audits.filter.from">from</span>
                </div>
                <input type="date" class="form-control" name="start" [(ngModel)]="fromDate" (ngModelChange)="transition()" required/>

                <div class="input-group-append">
                    <span class="input-group-text" jhiTranslate="audits.filter.to">To</span>
                </div>
                <input type="date" class="form-control" name="end" [(ngModel)]="toDate" (ngModelChange)="transition()" required/>
            </div>
        </div>
    </div>

    <div class="alert alert-warning" *ngIf="audits?.length === 0">
        <span jhiTranslate="audits.notFound">No audit found</span>
    </div>

    <div class="table-responsive" *ngIf="audits?.length > 0">
        <table class="table table-sm table-striped"  aria-describedby="audits-page-heading">
            <thead [ngSwitch]="canLoad()">
            <tr jhiSort [(predicate)]="predicate" [(ascending)]="ascending" [callback]="transition.bind(this)" *ngSwitchCase="true">
                <th scope="col" jhiSortBy="auditEventDate"><span jhiTranslate="audits.table.header.date">Date</span> <fa-icon [icon]="'sort'"></fa-icon></th>
                <th scope="col" jhiSortBy="principal"><span jhiTranslate="audits.table.header.principal">User</span> <fa-icon [icon]="'sort'"></fa-icon></th>
                <th scope="col" jhiSortBy="auditEventType"><span jhiTranslate="audits.table.header.status">State</span> <fa-icon [icon]="'sort'"></fa-icon></th>
                <th scope="col"><span jhiTranslate="audits.table.header.data">Extra data</span></th>
            </tr>
            <tr *ngSwitchCase="false">
                <th scope="col"><span jhiTranslate="audits.table.header.date">Date</span></th>
                <th scope="col"><span jhiTranslate="audits.table.header.principal">User</span></th>
                <th scope="col"><span jhiTranslate="audits.table.header.status">State</span></th>
                <th scope="col"><span jhiTranslate="audits.table.header.data">Extra data</span></th>
            </tr>
            </thead>
            <tbody>
            <tr *ngFor="let audit of audits">
                <td><span>{{audit.timestamp| date:'medium'}}</span></td>
                <td><small>{{audit.principal}}</small></td>
                <td>{{audit.type}}</td>
                <td>
                    <span *ngIf="audit.data" ng-show="audit.data.message">{{audit.data.message}}</span>
                    <span *ngIf="audit.data" ng-show="audit.data.remoteAddress"><span jhiTranslate="audits.table.data.remoteAddress">Remote Address</span> {{audit.data.remoteAddress}}</span>
                </td>
            </tr>
            </tbody>
        </table>
    </div>

    <div *ngIf="audits?.length > 0">
        <div class="row justify-content-center">
            <jhi-item-count [page]="page" [total]="totalItems" [itemsPerPage]="itemsPerPage"></jhi-item-count>
        </div>
        <div class="row justify-content-center">
            <ngb-pagination [collectionSize]="totalItems" [(page)]="page" [pageSize]="itemsPerPage" [maxSize]="5" [rotate]="true" [boundaryLinks]="true" (pageChange)="loadPage(page)" [disabled]="!canLoad()"></ngb-pagination>
        </div>
    </div>
</div>
